package net.jlibrary.computer.action;

import net.jlibrary.student.action.vo.StudentVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import net.jlibrary.common.core.entity.Pagination;
import net.jlibrary.common.core.entity.PaginationParam;
import net.jlibrary.computer.action.vo.ComputerVo;
import net.jlibrary.computer.service.IComputerManager;

@RestController
@RequestMapping("/computer")
public class ComputerAction {

	@Autowired
	private IComputerManager computerManager;

	@RequestMapping(value="/computerView",method = {RequestMethod.GET})
	public ModelAndView view() {
		
		return new ModelAndView("/computer/computerView");
	}

@RequestMapping(value="/selectComputerList",method = {RequestMethod.POST})
	public Pagination computerData(ComputerVo computerVo, PaginationParam param) {
	Pagination pagination = computerManager.listsPage(computerVo, param);
	System.out.println(pagination.getRows());
	return pagination;
	}

//	表单初始化信息
	@RequestMapping(value="/computerFormInit",method = {RequestMethod.GET})
	public ComputerVo computerFormInit(){
		ComputerVo computerVo = new ComputerVo();
		return computerVo;
	}
//	保存电脑信息
	@RequestMapping(value="/saveComputer",method = {RequestMethod.POST})
	public ModelMap saveStudent(@ModelAttribute("vm") ComputerVo computerVo){
		computerManager.save(computerVo);
		ModelMap modelMap = new ModelMap();
		modelMap.put("success", true);
		return modelMap;
	}
//	详细单个电脑信息
	@RequestMapping(value="/detailComputer",method = {RequestMethod.GET})
	public ComputerVo detail(ComputerVo computerVo){
		computerVo = computerManager.get(computerVo);
		return computerVo;
	}

//	删除电脑信息
	@RequestMapping(value="/deleteComputer",method = {RequestMethod.POST})
	public ModelMap delete(Long id){
		if (!StringUtils.isNotBlank(id.toString())){
			return null;
		}
		ComputerVo computerVo = new ComputerVo();
		computerVo.setId(id);
		computerManager.delete(computerVo);
		ModelMap modelMap = new ModelMap();
		modelMap.put("success", true);
		return modelMap;
	}
//	修改数据
	@RequestMapping(value="/updateComputer",method = {RequestMethod.POST})
	public ModelMap update(@ModelAttribute("vm") ComputerVo computerVo){
		computerManager.update(computerVo);
		ModelMap modelMap = new ModelMap();
		modelMap.put("success", true);
		return modelMap;
	}

//	恢复电脑信息
	@RequestMapping(value="/renewComputer",method = {RequestMethod.POST})
	public ModelMap renew(Long id){
		ComputerVo computerVo = new ComputerVo();
		computerVo.setId(id);
		computerManager.renew(computerVo);
		ModelMap modelMap = new ModelMap();
		modelMap.put("success", true);
		return modelMap;
	}



}
